package com.extra_archive.project.iisu.controller
{
	import iisu.iisuEvent.TriggerEvent;
	import flash.ui.Keyboard;
	import iisu.iisuEvent.ZoomEvent;
	import iisu.iisuEvent.ClickEvent;
	import iisu.iisuEvent.HandsEvent;
	import iisu.iisuEvent.PressReleaseEvent;
	import iisu.iisuEvent.UsersEvent;

	import com.extra_archive.framework.core.mvc.controller.IkeyboardController;
	import com.extra_archive.framework.core.mvc.model.IModel;
	import com.extra_archive.project.iisu.model.ARModel;
	import com.extra_archive.project.iisu.model.ARModelEvent;

	import flash.events.KeyboardEvent;

	/**
	 * @author vkimone
	 */
	public class ARKeyboardController implements IkeyboardController 
	{
		private var _model : ARModel;

		public function ARKeyboardController(model : IModel)
		{
			_model = ARModel(model);
			
			_model.applicationContainer.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
			_model.applicationContainer.stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
		}

		public function update() : void
		{
		}

		public function keyDownHandler(event : KeyboardEvent) : void
		{
		}

		public function keyUpHandler(event : KeyboardEvent) : void
		{
			switch( event.keyCode ) 
			{
				/**
				 * set debug view visible
				 */
				case "I".charCodeAt():
					_model.isDebugViewActive = !_model.isDebugViewActive;
					break;	
				/**
				 * dispatch gesture event
				 */
				case "M".charCodeAt():
					_model.gesture.dispatchEvent(new UsersEvent(UsersEvent.USERS_START_TOUCHING));
					break;
					
				case "C".charCodeAt():
					_model.gesture.dispatchEvent(new ClickEvent(0, 0));
					break;	
					
				case "P".charCodeAt():
					_model.gesture.dispatchEvent(new PressReleaseEvent(PressReleaseEvent.PRESS_RIGHT));
					break;	
					
				case "W".charCodeAt():
					_model.gesture.dispatchEvent(new PressReleaseEvent(PressReleaseEvent.RELEASE_TWO_HANDS));
					break;
					
				case "U".charCodeAt():
					_model.gesture.dispatchEvent(new TriggerEvent(TriggerEvent.TRIGGER_UP));
					break;	
					
				case "T".charCodeAt():
					_model.gesture.dispatchEvent(new HandsEvent(HandsEvent.TWO_HANDS));
					break;	
					
				case "L".charCodeAt():
					_model.dispatchEvent(new ARModelEvent(ARModelEvent.DETAIL_TO_LIST));
					break;
					
				case "D".charCodeAt():
					_model.dispatchEvent(new ARModelEvent(ARModelEvent.LIST_TO_DETAIL));
					break;	
					
					
				
				case Keyboard.NUMPAD_ADD:
					_model.gesture.dispatchEvent(new ZoomEvent(ZoomEvent.ZOOM_IN));
					break;											
			}
		}
	}
}
